//
//  userAccount.swift
//  WeiBo
//
//  Created by LTX on 2016/11/8.
//  Copyright © 2016年 LTX. All rights reserved.
//

import UIKit

class userAccount: NSObject, NSCoding {

    // 授权AccessToken
    var access_token :String?
    // 过期时间秒
    var expires_in : TimeInterval = 0.0 {
        didSet{
          expires_date = NSDate(timeIntervalSinceNow:expires_in)
        }
    }
    
    
    // 用户id
    var uid : String?
    
    //过期时间
    var expires_date : NSDate?
    
    
    // MARK:- 自定义构造函数
    init(dic:[String : AnyObject]) {
        super.init()
        setValuesForKeys(dic)
        
    }
    
    //一定要重写这个方法
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }
    
    //昵称
    var screen_name : String?
    
    // 头像地址
    var avatar_large : String?
    
    
    
    
    //重写description
    override var description: String{
        
       return dictionaryWithValues(forKeys: ["access_token", "expires_date", "uid", "screen_name", "avatar_large"]).description
        
    }
    
    
    //解档
    required init?(coder aDecoder: NSCoder) {
        
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        uid = aDecoder.decodeObject(forKey: "uid") as? String
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as? NSDate
        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as? String
        screen_name = aDecoder.decodeObject(forKey: "screen_name") as? String
    }
    
    
    //归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(avatar_large, forKey: "avatar_large")
        aCoder.encode(screen_name, forKey: "screen_name")
    }
    
}
